package edu.uta.iconverter.util;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;


public class ReadWriteTextFile {
	private final String fFileName;
	
	public ReadWriteTextFile(String aFileName) {
		fFileName = aFileName;
	}
	
	 /** Read the contents of the given file. */
	public StringBuilder read() throws IOException {
		log("Reading from file.");
		StringBuilder text = new StringBuilder();
		String NL = System.getProperty("line.separator");
		Scanner scanner = new Scanner(new FileInputStream(fFileName));
		try {
			while (scanner.hasNextLine()) {
				text.append(scanner.nextLine() + NL);
			}
		}
		finally {
		  scanner.close();
		}
		//log("Text read in: " + text);
		return text;
	}
	
	static String getCurrentDirectory()
	{
		String cwd = null;
		try{
			cwd = new java.io.File( "." ).getCanonicalPath();
		} 
		catch (java.io.IOException e){
		}
		System.out.println("cwd = " + cwd);
		// Which may or may not be the same as:
		String userDir = System.getProperty( "user.dir" );
		System.out.println("userDir = " + userDir );
		return userDir;
	}
	
	private void log(String aMessage) {
		System.out.println(aMessage);
	}
}
